/**
 @file ctc_efd.h

 @author  Copyright (C) 2014 Centec Networks Inc.  All rights reserved.

 @date 2014-10-28

 @version v3.0

   This file contains all efd related data structure, enum, macro and proto.
*/

#ifndef _CTC_EFD_H
#define _CTC_EFD_H
#ifdef __cplusplus
extern "C" {
#endif
/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "ctc_const.h"

/****************************************************************
*
* Defines and Macros
*
****************************************************************/

#define CTC_EFD_FLOW_ID_ARRAY_MAX       64

/**
 @brief  global control type
*/
enum ctc_efd_global_control_type_e
{
    CTC_EFD_GLOBAL_MODE_TCP,               /**< [GG.D2.TM.TMM.AT]Only TCP packets do EFD. value: bool*, TRUE or FALSE */
    CTC_EFD_GLOBAL_PRIORITY_EN,            /**< [GG]When enable, the elephant flow will use the configed priority. value: bool*, TRUE or FALSE */
    CTC_EFD_GLOBAL_PRIORITY,               /**< [GG]Config global priority for the elephant flow.value: <0-15> */
    CTC_EFD_GLOBAL_COLOR_EN,               /**< [GG]When enable, the elephant flow will use the configed color. value: bool*, TRUE or FALSE */
    CTC_EFD_GLOBAL_COLOR,                  /**< [GG]Config global color for the elephant flow. value: 1-red 2-yellow 3-green */
    CTC_EFD_GLOBAL_MIN_PKT_LEN,            /**< [GG.D2.TM.TMM.AT]Only packet length > MIN_PKT_LEN value do EFD. value:  0-0x3fff, 0 means all packet length do EFD */
    CTC_EFD_GLOBAL_DETECT_RATE,            /**< [GG.D2.TM.TMM.AT]Min flow rate to detect as Elephant Flow, unit:kbps. */
    CTC_EFD_GLOBAL_IPG_EN,                 /**< [GG.D2.TM.TMM.AT]Ipg is considered in EFD. value: bool*, TRUE or FALSE*/
    CTC_EFD_GLOBAL_EFD_EN,                 /**< [D2.TM.TMM.AT]Config global EFD enable. value: bool*, TRUE or FALSE default is enable*/
    CTC_EFD_GLOBAL_PPS_EN,                 /**< [D2.TM.TMM.AT]Do EFD by pps. value: bool*, TRUE:pps ,FALSE:bps*/
    CTC_EFD_GLOBAL_FUZZY_MATCH_EN,         /**< [D2.TM.TMM.AT]Do EFD using fuzzy match mode. value: bool*, TRUE:fuzzy match mode, no limit to flow table ,FALSE:exact match mode, limit to flow table*/
    CTC_EFD_GLOBAL_RANDOM_LOG_EN,          /**< [D2.TM.TMM.AT]When enable, the elephant flow will use the configed log to cpu. value: bool*, TRUE or FALSE */
    CTC_EFD_GLOBAL_RANDOM_LOG_RATE,        /**< [D2.TM.TMM.AT]Config Threshold rate to cpu.percent:before tmm (2^rate-1)/(2^15),from tmm (2^rate)/(2^15), value: <0-15> */
    CTC_EFD_GLOBAL_DETECT_GRANU,           /**< [GG.D2.TM.TMM.AT]Packet length update granularity for detect, value: <0-3>, 0:16Byte, 1:8Byte, 2:4Byte, 3:32Byte*/
    CTC_EFD_GLOBAL_DETECT_INTERVAL,        /**< [GG.D2.TM.TMM.AT]Detect efd flow (learning) and aging time interval, unit:1ms*/
    CTC_EFD_GLOBAL_AGING_MULT,             /**< [GG.D2.TM.TMM.AT]Aging multiplier, value: 0-7, aging time=DetectInterval*AgingMult */
    CTC_EFD_GLOBAL_REDIRECT,               /**< [GG.D2.TM.TMM.AT] Config efd flow redirect nexthop id, value: uint32* array, array[0] is flowId, array[1] is nhId;d2/tm only support global redirect */
    CTC_EFD_GLOBAL_FLOW_ACTIVE_BMP,        /**< [GG.D2.TM.TMM] Get active elephant flow bitmap based on flow id, value: uint32* bitmap, should at least have 2K bits in GG, and 1k bits in D2, and 8K in TMM*/
    CTC_EFD_GLOBAL_FLOW_QUERY,             /**< [TMM.AT]Get active elephant flow based on flow id, value: refer to ctc_efd_query_rst_t */
    CTC_EFD_GLOBAL_DROP_PKT_EN,            /**< [AT]value: bool* TRUE or FALSE,FALSE:only non_discard packet do EFD; TRUE:all packet do EFD,default is disable */

    CTC_EFD_GLOBAL_CONTROL_MAX
};
typedef enum ctc_efd_global_control_type_e ctc_efd_global_control_type_t;


/**
@brief  efd data of hardware
*/
struct ctc_efd_data_s
{
    uint16 count;                                       /**<[GG.D2.TM.TMM.AT]Flow id number*/
    uint16 rsv;
    uint32 flow_id_array[CTC_EFD_FLOW_ID_ARRAY_MAX];    /**<[GG.D2.TM.TMM.AT]Use array to store flow id */
};
typedef struct ctc_efd_data_s ctc_efd_data_t;

struct ctc_efd_query_rst_s
{
    uint32  start_id;                              /**<[TMM.AT]Start flow id for query */
    uint8   pp_id;                                      /**<[AT]PP id, for arctic,users can indicate one pp to traverse*/
    uint8   is_end;                                     /**<[TMM.AT]if is_end == 1, indicate the end of traverse totally*/
    uint16  array_cnt;                                  /**<[TMM.AT]Indicate flow id bitmap array number for one traverse */
    uint32* flow_id_array;                              /**<[TMM.AT]Flow id bitmap array*/
};
typedef struct ctc_efd_query_rst_s ctc_efd_query_rst_t;


/**
@brief  callback of efd for aging
*/
typedef void (* ctc_efd_fn_t)(ctc_efd_data_t* info, void* userdata) ;  /**< [GG.D2.TM.TMM.AT]Callback function to get aging flowId from DMA */


#ifdef __cplusplus
}
#endif

#endif

